
function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

  function getOption(){
        var str = $("sel_opt option:selected").val();   //获得选中的值
        $.ajax({
            type:"post",
            dataType:"json",
            url:"/publish/news_publish",
            data:{'select':str},
            success:function(msg){

            }
        });
    }

$(function () {

    $(".release_form").submit(function (e) {
        e.preventDefault()

        // 发布新闻, ajaxSubmit属于表单提交
        $(this).ajaxSubmit({
            //是为了处理富文本(可以有颜色,大小)
            beforeSubmit: function (request) {
                // 在提交之前，对参数进行处理
                for(var i=0; i<request.length; i++) {
                    var item = request[i]
                    if (item["name"] == "content") {
                        item["value"] = tinyMCE.activeEditor.getContent()
                    }
                }
            },
            url: "/publish/news_publish",
            type: "POST",
            datatype:"json",
            headers: {
                "X-CSRFToken": getCookie('csrf_token')
            },
            success: function (resp) {
                if (resp.errno == "0") {

                    // 返回上一页，刷新数据
                    location.href ="/"
                }else {
                    alert(resp.errmsg)
                }
            }
        })

    })
})